<!doctype html>
<html class="no-js" lang="en, zh-CN" data-content_root="../../">
  <head><meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width,initial-scale=1"/>
    <meta name="color-scheme" content="light dark"><meta name="generator" content="Docutils 0.19: https://docutils.sourceforge.io/" />
<link rel="index" title="Index" href="../../genindex.html" /><link rel="search" title="Search" href="../../search.html" /><link rel="next" title="Bridge Converter" href="bridge_converter.html" /><link rel="prev" title="Object Converter" href="object_converter.html" />

    <link rel="shortcut icon" href="../../_static/logo.ico"/><!-- Generated with Sphinx 7.2.6 and Furo 2023.09.10 -->
        <title>Proxy Converter - Javet 3.0.0 documentation</title>
      <link rel="stylesheet" type="text/css" href="../../_static/pygments.css?v=a746c00c" />
    <link rel="stylesheet" type="text/css" href="../../_static/styles/furo.css?v=135e06be" />
    <link rel="stylesheet" type="text/css" href="../../_static/tabs.css?v=4c969af8" />
    <link rel="stylesheet" type="text/css" href="../../_static/styles/furo-extensions.css?v=36a5483c" />
    <link rel="stylesheet" type="text/css" href="../../_static/css/custom.css?v=c2631171" />
    
    


<style>
  body {
    --color-code-background: #f8f8f8;
  --color-code-foreground: black;
  
  }
  @media not print {
    body[data-theme="dark"] {
      --color-code-background: #202020;
  --color-code-foreground: #d0d0d0;
  
    }
    @media (prefers-color-scheme: dark) {
      body:not([data-theme="light"]) {
        --color-code-background: #202020;
  --color-code-foreground: #d0d0d0;
  
      }
    }
  }
</style></head>
  <body>
    
    <script>
      document.body.dataset.theme = localStorage.getItem("theme") || "auto";
    </script>
    

<svg xmlns="http://www.w3.org/2000/svg" style="display: none;">
  <symbol id="svg-toc" viewBox="0 0 24 24">
    <title>Contents</title>
    <svg stroke="currentColor" fill="currentColor" stroke-width="0" viewBox="0 0 1024 1024">
      <path d="M408 442h480c4.4 0 8-3.6 8-8v-56c0-4.4-3.6-8-8-8H408c-4.4 0-8 3.6-8 8v56c0 4.4 3.6 8 8 8zm-8 204c0 4.4 3.6 8 8 8h480c4.4 0 8-3.6 8-8v-56c0-4.4-3.6-8-8-8H408c-4.4 0-8 3.6-8 8v56zm504-486H120c-4.4 0-8 3.6-8 8v56c0 4.4 3.6 8 8 8h784c4.4 0 8-3.6 8-8v-56c0-4.4-3.6-8-8-8zm0 632H120c-4.4 0-8 3.6-8 8v56c0 4.4 3.6 8 8 8h784c4.4 0 8-3.6 8-8v-56c0-4.4-3.6-8-8-8zM115.4 518.9L271.7 642c5.8 4.6 14.4.5 14.4-6.9V388.9c0-7.4-8.5-11.5-14.4-6.9L115.4 505.1a8.74 8.74 0 0 0 0 13.8z"/>
    </svg>
  </symbol>
  <symbol id="svg-menu" viewBox="0 0 24 24">
    <title>Menu</title>
    <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor"
      stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather-menu">
      <line x1="3" y1="12" x2="21" y2="12"></line>
      <line x1="3" y1="6" x2="21" y2="6"></line>
      <line x1="3" y1="18" x2="21" y2="18"></line>
    </svg>
  </symbol>
  <symbol id="svg-arrow-right" viewBox="0 0 24 24">
    <title>Expand</title>
    <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor"
      stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather-chevron-right">
      <polyline points="9 18 15 12 9 6"></polyline>
    </svg>
  </symbol>
  <symbol id="svg-sun" viewBox="0 0 24 24">
    <title>Light mode</title>
    <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor"
      stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" class="feather-sun">
      <circle cx="12" cy="12" r="5"></circle>
      <line x1="12" y1="1" x2="12" y2="3"></line>
      <line x1="12" y1="21" x2="12" y2="23"></line>
      <line x1="4.22" y1="4.22" x2="5.64" y2="5.64"></line>
      <line x1="18.36" y1="18.36" x2="19.78" y2="19.78"></line>
      <line x1="1" y1="12" x2="3" y2="12"></line>
      <line x1="21" y1="12" x2="23" y2="12"></line>
      <line x1="4.22" y1="19.78" x2="5.64" y2="18.36"></line>
      <line x1="18.36" y1="5.64" x2="19.78" y2="4.22"></line>
    </svg>
  </symbol>
  <symbol id="svg-moon" viewBox="0 0 24 24">
    <title>Dark mode</title>
    <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor"
      stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" class="icon-tabler-moon">
      <path stroke="none" d="M0 0h24v24H0z" fill="none" />
      <path d="M12 3c.132 0 .263 0 .393 0a7.5 7.5 0 0 0 7.92 12.446a9 9 0 1 1 -8.313 -12.454z" />
    </svg>
  </symbol>
  <symbol id="svg-sun-half" viewBox="0 0 24 24">
    <title>Auto light/dark mode</title>
    <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor"
      stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" class="icon-tabler-shadow">
      <path stroke="none" d="M0 0h24v24H0z" fill="none"/>
      <circle cx="12" cy="12" r="9" />
      <path d="M13 12h5" />
      <path d="M13 15h4" />
      <path d="M13 18h1" />
      <path d="M13 9h4" />
      <path d="M13 6h1" />
    </svg>
  </symbol>
</svg>

<input type="checkbox" class="sidebar-toggle" name="__navigation" id="__navigation">
<input type="checkbox" class="sidebar-toggle" name="__toc" id="__toc">
<label class="overlay sidebar-overlay" for="__navigation">
  <div class="visually-hidden">Hide navigation sidebar</div>
</label>
<label class="overlay toc-overlay" for="__toc">
  <div class="visually-hidden">Hide table of contents sidebar</div>
</label>



<div class="page">
  <header class="mobile-header">
    <div class="header-left">
      <label class="nav-overlay-icon" for="__navigation">
        <div class="visually-hidden">Toggle site navigation sidebar</div>
        <i class="icon"><svg><use href="#svg-menu"></use></svg></i>
      </label>
    </div>
    <div class="header-center">
      <a href="../../index.html"><div class="brand">Javet 3.0.0 documentation</div></a>
    </div>
    <div class="header-right">
      <div class="theme-toggle-container theme-toggle-header">
        <button class="theme-toggle">
          <div class="visually-hidden">Toggle Light / Dark / Auto color theme</div>
          <svg class="theme-icon-when-auto"><use href="#svg-sun-half"></use></svg>
          <svg class="theme-icon-when-dark"><use href="#svg-moon"></use></svg>
          <svg class="theme-icon-when-light"><use href="#svg-sun"></use></svg>
        </button>
      </div>
      <label class="toc-overlay-icon toc-header-icon" for="__toc">
        <div class="visually-hidden">Toggle table of contents sidebar</div>
        <i class="icon"><svg><use href="#svg-toc"></use></svg></i>
      </label>
    </div>
  </header>
  <aside class="sidebar-drawer">
    <div class="sidebar-container">
      
      <div class="sidebar-sticky"><a class="sidebar-brand" href="../../index.html">
  
  <div class="sidebar-logo-container">
    <img class="sidebar-logo" src="../../_static/logo.png" alt="Logo"/>
  </div>
  
  <span class="sidebar-brand-text">Javet 3.0.0 documentation</span>
  
</a><form class="sidebar-search-container" method="get" action="../../search.html" role="search">
  <input class="sidebar-search" placeholder="Search" name="q" aria-label="Search">
  <input type="hidden" name="check_keywords" value="yes">
  <input type="hidden" name="area" value="default">
</form>
<div id="searchbox"></div><div class="sidebar-scroll"><div class="sidebar-tree">
  <ul class="current">
<li class="toctree-l1 has-children"><a class="reference internal" href="../../tutorial/index.html">Tutorial</a><input class="toctree-checkbox" id="toctree-checkbox-1" name="toctree-checkbox-1" role="switch" type="checkbox"/><label for="toctree-checkbox-1"><div class="visually-hidden">Toggle navigation of Tutorial</div><i class="icon"><svg><use href="#svg-arrow-right"></use></svg></i></label><ul>
<li class="toctree-l2 has-children"><a class="reference internal" href="../../tutorial/basic/index.html">Basic</a><input class="toctree-checkbox" id="toctree-checkbox-2" name="toctree-checkbox-2" role="switch" type="checkbox"/><label for="toctree-checkbox-2"><div class="visually-hidden">Toggle navigation of Basic</div><i class="icon"><svg><use href="#svg-arrow-right"></use></svg></i></label><ul>
<li class="toctree-l3"><a class="reference internal" href="../../tutorial/basic/installation.html">Installation</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../tutorial/basic/hello_javet.html">Hello Javet</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../tutorial/basic/javet_shell.html">Javet Shell</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../tutorial/basic/interception.html">Interception</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../tutorial/basic/engine_pool.html">Javet Engine Pool</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../tutorial/basic/node_js_mode_and_v8_mode.html">Node.js Mode and V8 Mode</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../tutorial/basic/spring_integration.html">Spring Integration</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../tutorial/basic/polyfill.html">Polyfill</a></li>
</ul>
</li>
<li class="toctree-l2 has-children"><a class="reference internal" href="../../tutorial/advanced/index.html">Advanced</a><input class="toctree-checkbox" id="toctree-checkbox-3" name="toctree-checkbox-3" role="switch" type="checkbox"/><label for="toctree-checkbox-3"><div class="visually-hidden">Toggle navigation of Advanced</div><i class="icon"><svg><use href="#svg-arrow-right"></use></svg></i></label><ul>
<li class="toctree-l3"><a class="reference internal" href="../../tutorial/advanced/interact_with_node_js.html">Interact with Node.js</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../tutorial/advanced/object_converter.html">Object Converter</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../tutorial/advanced/java_and_javascript_interop.html">Java and JavaScript Interop</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../tutorial/advanced/expose_json_node_in_v8.html">Expose JsonNode in V8</a></li>
</ul>
</li>
<li class="toctree-l2 has-children"><a class="reference internal" href="../../tutorial/migration_guides/index.html">Migration Guides</a><input class="toctree-checkbox" id="toctree-checkbox-4" name="toctree-checkbox-4" role="switch" type="checkbox"/><label for="toctree-checkbox-4"><div class="visually-hidden">Toggle navigation of Migration Guides</div><i class="icon"><svg><use href="#svg-arrow-right"></use></svg></i></label><ul>
<li class="toctree-l3"><a class="reference internal" href="../../tutorial/migration_guides/migrate_from_j2v8.html">Migrate from J2V8</a></li>
</ul>
</li>
</ul>
</li>
<li class="toctree-l1 current has-children"><a class="reference internal" href="../index.html">Reference</a><input checked="" class="toctree-checkbox" id="toctree-checkbox-5" name="toctree-checkbox-5" role="switch" type="checkbox"/><label for="toctree-checkbox-5"><div class="visually-hidden">Toggle navigation of Reference</div><i class="icon"><svg><use href="#svg-arrow-right"></use></svg></i></label><ul class="current">
<li class="toctree-l2"><a class="reference internal" href="../javadoc/index.html">API Reference</a></li>
<li class="toctree-l2 has-children"><a class="reference internal" href="../v8_values/index.html">V8 Values</a><input class="toctree-checkbox" id="toctree-checkbox-6" name="toctree-checkbox-6" role="switch" type="checkbox"/><label for="toctree-checkbox-6"><div class="visually-hidden">Toggle navigation of V8 Values</div><i class="icon"><svg><use href="#svg-arrow-right"></use></svg></i></label><ul>
<li class="toctree-l3"><a class="reference internal" href="../v8_values/v8_collection.html">V8 Collection</a></li>
<li class="toctree-l3"><a class="reference internal" href="../v8_values/v8_function.html">V8 Function</a></li>
<li class="toctree-l3"><a class="reference internal" href="../v8_values/v8_promise.html">V8 Promise</a></li>
</ul>
</li>
<li class="toctree-l2 current has-children"><a class="reference internal" href="index.html">Converters</a><input checked="" class="toctree-checkbox" id="toctree-checkbox-7" name="toctree-checkbox-7" role="switch" type="checkbox"/><label for="toctree-checkbox-7"><div class="visually-hidden">Toggle navigation of Converters</div><i class="icon"><svg><use href="#svg-arrow-right"></use></svg></i></label><ul class="current">
<li class="toctree-l3"><a class="reference internal" href="primitive_converter.html">Primitive Converter</a></li>
<li class="toctree-l3"><a class="reference internal" href="object_converter.html">Object Converter</a></li>
<li class="toctree-l3 current current-page"><a class="current reference internal" href="#">Proxy Converter</a></li>
<li class="toctree-l3"><a class="reference internal" href="bridge_converter.html">Bridge Converter</a></li>
<li class="toctree-l3"><a class="reference internal" href="custom_converter.html">Custom Converter</a></li>
</ul>
</li>
<li class="toctree-l2 has-children"><a class="reference internal" href="../resource_management/index.html">Resource Management</a><input class="toctree-checkbox" id="toctree-checkbox-8" name="toctree-checkbox-8" role="switch" type="checkbox"/><label for="toctree-checkbox-8"><div class="visually-hidden">Toggle navigation of Resource Management</div><i class="icon"><svg><use href="#svg-arrow-right"></use></svg></i></label><ul>
<li class="toctree-l3"><a class="reference internal" href="../resource_management/load_and_unload.html">Load and Unload</a></li>
<li class="toctree-l3"><a class="reference internal" href="../resource_management/lock.html">Know the Lock</a></li>
<li class="toctree-l3"><a class="reference internal" href="../resource_management/memory_management.html">Memory Management</a></li>
<li class="toctree-l3"><a class="reference internal" href="../resource_management/modularization.html">Modularization</a></li>
<li class="toctree-l3"><a class="reference internal" href="../resource_management/performance.html">Javet Performance</a></li>
</ul>
</li>
<li class="toctree-l2 has-children"><a class="reference internal" href="../troubleshooting/index.html">Troubleshooting</a><input class="toctree-checkbox" id="toctree-checkbox-9" name="toctree-checkbox-9" role="switch" type="checkbox"/><label for="toctree-checkbox-9"><div class="visually-hidden">Toggle navigation of Troubleshooting</div><i class="icon"><svg><use href="#svg-arrow-right"></use></svg></i></label><ul>
<li class="toctree-l3"><a class="reference internal" href="../troubleshooting/error_codes.html">Error Codes</a></li>
<li class="toctree-l3"><a class="reference internal" href="../troubleshooting/logging.html">Logging</a></li>
<li class="toctree-l3"><a class="reference internal" href="../troubleshooting/termination.html">Termination</a></li>
</ul>
</li>
<li class="toctree-l2 has-children"><a class="reference internal" href="../tips/index.html">Tips</a><input class="toctree-checkbox" id="toctree-checkbox-10" name="toctree-checkbox-10" role="switch" type="checkbox"/><label for="toctree-checkbox-10"><div class="visually-hidden">Toggle navigation of Tips</div><i class="icon"><svg><use href="#svg-arrow-right"></use></svg></i></label><ul>
<li class="toctree-l3"><a class="reference internal" href="../tips/best_practices.html">Best Practices</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../todo_list.html">TODO List</a></li>
</ul>
</li>
<li class="toctree-l1 has-children"><a class="reference internal" href="../../release_notes/index.html">Release Notes</a><input class="toctree-checkbox" id="toctree-checkbox-11" name="toctree-checkbox-11" role="switch" type="checkbox"/><label for="toctree-checkbox-11"><div class="visually-hidden">Toggle navigation of Release Notes</div><i class="icon"><svg><use href="#svg-arrow-right"></use></svg></i></label><ul>
<li class="toctree-l2"><a class="reference internal" href="../../release_notes/release_notes_3_0.html">Release Notes 3.0.x</a></li>
</ul>
</li>
<li class="toctree-l1 has-children"><a class="reference internal" href="../../faq/index.html">FAQ</a><input class="toctree-checkbox" id="toctree-checkbox-12" name="toctree-checkbox-12" role="switch" type="checkbox"/><label for="toctree-checkbox-12"><div class="visually-hidden">Toggle navigation of FAQ</div><i class="icon"><svg><use href="#svg-arrow-right"></use></svg></i></label><ul>
<li class="toctree-l2 has-children"><a class="reference internal" href="../../faq/background/index.html">Background</a><input class="toctree-checkbox" id="toctree-checkbox-13" name="toctree-checkbox-13" role="switch" type="checkbox"/><label for="toctree-checkbox-13"><div class="visually-hidden">Toggle navigation of Background</div><i class="icon"><svg><use href="#svg-arrow-right"></use></svg></i></label><ul>
<li class="toctree-l3"><a class="reference internal" href="../../faq/background/history_with_j2v8.html">History with J2V8</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../faq/background/what_is_the_motivation.html">What is the Motivation?</a></li>
</ul>
</li>
<li class="toctree-l2 has-children"><a class="reference internal" href="../../faq/development/index.html">Development</a><input class="toctree-checkbox" id="toctree-checkbox-14" name="toctree-checkbox-14" role="switch" type="checkbox"/><label for="toctree-checkbox-14"><div class="visually-hidden">Toggle navigation of Development</div><i class="icon"><svg><use href="#svg-arrow-right"></use></svg></i></label><ul>
<li class="toctree-l3"><a class="reference internal" href="../../faq/development/how_to_think_in_javet.html">How to Think in Javet?</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../faq/development/where_are_es6_api_in_v8_mode.html">Where are ES6 API in V8 Mode?</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../faq/development/where_are_the_examples.html">Where are the Examples?</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../faq/development/why_is_the_inspector_disabled_in_node_js_mode.html">Why is the Inspector Disabled in Node.js Mode?</a></li>
</ul>
</li>
<li class="toctree-l2 has-children"><a class="reference internal" href="../../faq/environment/index.html">Environment</a><input class="toctree-checkbox" id="toctree-checkbox-15" name="toctree-checkbox-15" role="switch" type="checkbox"/><label for="toctree-checkbox-15"><div class="visually-hidden">Toggle navigation of Environment</div><i class="icon"><svg><use href="#svg-arrow-right"></use></svg></i></label><ul>
<li class="toctree-l3"><a class="reference internal" href="../../faq/environment/can_javet_support_legacy_linux.html">Can Javet Support Legacy Linux?</a></li>
</ul>
</li>
<li class="toctree-l2 has-children"><a class="reference internal" href="../../faq/troubleshooting/index.html">Troubleshooting</a><input class="toctree-checkbox" id="toctree-checkbox-16" name="toctree-checkbox-16" role="switch" type="checkbox"/><label for="toctree-checkbox-16"><div class="visually-hidden">Toggle navigation of Troubleshooting</div><i class="icon"><svg><use href="#svg-arrow-right"></use></svg></i></label><ul>
<li class="toctree-l3"><a class="reference internal" href="../../faq/troubleshooting/a_dynamic_link_library_dll_initialization_routine_failed.html">A dynamic link library (DLL) initialization routine failed</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../faq/troubleshooting/can_i18n_be_supported.html">Can i18n be Supported?</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../faq/troubleshooting/can_i_debug_javet_in_chrome_dev_tools.html">Can I Debug Javet in Chrome DevTools?</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../faq/troubleshooting/why_node_js_crashes_when_being_closed.html">Why Node.js Crashes When being Closed?</a></li>
</ul>
</li>
</ul>
</li>
<li class="toctree-l1 has-children"><a class="reference internal" href="../../development/index.html">Development</a><input class="toctree-checkbox" id="toctree-checkbox-17" name="toctree-checkbox-17" role="switch" type="checkbox"/><label for="toctree-checkbox-17"><div class="visually-hidden">Toggle navigation of Development</div><i class="icon"><svg><use href="#svg-arrow-right"></use></svg></i></label><ul>
<li class="toctree-l2"><a class="reference internal" href="../../development/tools.html">Development Tools</a></li>
<li class="toctree-l2 has-children"><a class="reference internal" href="../../development/build.html">Build Javet</a><input class="toctree-checkbox" id="toctree-checkbox-18" name="toctree-checkbox-18" role="switch" type="checkbox"/><label for="toctree-checkbox-18"><div class="visually-hidden">Toggle navigation of Build Javet</div><i class="icon"><svg><use href="#svg-arrow-right"></use></svg></i></label><ul>
<li class="toctree-l3"><a class="reference internal" href="../../development/build_javet_with_docker.html">Build Javet with Docker</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../development/build_javet_from_scratch.html">Build Javet from Scratch</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../../development/test.html">Test Javet</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../development/design.html">Javet Design</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../development/performance.html">Javet Performance</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../development/debug_with_chrome_developer_tools.html">Debug with Chrome Developer Tools</a></li>
</ul>
</li>
</ul>

</div>
</div>

      </div>
      
    </div>
  </aside>
  <div class="main">
    <div class="content">
      <div class="article-container">
        <a href="#" class="back-to-top muted-link">
          <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
            <path d="M13 20h-2V8l-5.5 5.5-1.42-1.42L12 4.16l7.92 7.92-1.42 1.42L13 8v12z"></path>
          </svg>
          <span>Back to top</span>
        </a>
        <div class="content-icon-container">
          
<div class="theme-toggle-container theme-toggle-content">
            <button class="theme-toggle">
              <div class="visually-hidden">Toggle Light / Dark / Auto color theme</div>
              <svg class="theme-icon-when-auto"><use href="#svg-sun-half"></use></svg>
              <svg class="theme-icon-when-dark"><use href="#svg-moon"></use></svg>
              <svg class="theme-icon-when-light"><use href="#svg-sun"></use></svg>
            </button>
          </div>
          <label class="toc-overlay-icon toc-content-icon" for="__toc">
            <div class="visually-hidden">Toggle table of contents sidebar</div>
            <i class="icon"><svg><use href="#svg-toc"></use></svg></i>
          </label>
        </div>
        <article role="main">
          <section id="proxy-converter">
<h1>Proxy Converter<a class="headerlink" href="#proxy-converter" title="Link to this heading">#</a></h1>
<p>Can I inject arbitrary Java objects and call all the API in JavaScript? Yes, <code class="docutils literal notranslate"><span class="pre">JavetProxyConverter</span></code> is designed for that. In general, the user experience is very much close to the one provided by GraalJS. As <code class="docutils literal notranslate"><span class="pre">JavetProxyConverter</span></code> opens almost the whole JVM to V8, it is very dangerous to allow end users to touch that V8 runtime, so <code class="docutils literal notranslate"><span class="pre">JavetProxyConverter</span></code> is not enabled by default. Here are the steps on how to enable that.</p>
<section id="usage">
<h2>Usage<a class="headerlink" href="#usage" title="Link to this heading">#</a></h2>
<section id="preparation">
<h3>Preparation<a class="headerlink" href="#preparation" title="Link to this heading">#</a></h3>
<div class="highlight-java notranslate"><div class="highlight"><pre><span></span><span class="c1">// Step 1: Create an instance of JavetProxyConverter.</span>
<span class="n">JavetProxyConverter</span><span class="w"> </span><span class="n">javetProxyConverter</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="k">new</span><span class="w"> </span><span class="n">JavetProxyConverter</span><span class="p">();</span>
<span class="c1">// Step 2: Set the V8Runtime converter to JavetProxyConverter.</span>
<span class="n">v8Runtime</span><span class="p">.</span><span class="na">setConverter</span><span class="p">(</span><span class="n">javetProxyConverter</span><span class="p">);</span>
</pre></div>
</div>
</section>
<section id="instance-file">
<h3>Instance: File<a class="headerlink" href="#instance-file" title="Link to this heading">#</a></h3>
<div class="highlight-java notranslate"><div class="highlight"><pre><span></span><span class="n">File</span><span class="w"> </span><span class="n">file</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="k">new</span><span class="w"> </span><span class="n">File</span><span class="p">(</span><span class="s">&quot;/tmp/i-am-not-accessible&quot;</span><span class="p">);</span>
<span class="n">v8Runtime</span><span class="p">.</span><span class="na">getGlobalObject</span><span class="p">().</span><span class="na">set</span><span class="p">(</span><span class="s">&quot;file&quot;</span><span class="p">,</span><span class="w"> </span><span class="n">file</span><span class="p">);</span>
<span class="n">assertEquals</span><span class="p">(</span><span class="n">file</span><span class="p">,</span><span class="w"> </span><span class="n">v8Runtime</span><span class="p">.</span><span class="na">getGlobalObject</span><span class="p">().</span><span class="na">getObject</span><span class="p">(</span><span class="s">&quot;file&quot;</span><span class="p">));</span>
<span class="n">assertEquals</span><span class="p">(</span><span class="n">file</span><span class="p">.</span><span class="na">exists</span><span class="p">(),</span><span class="w"> </span><span class="n">v8Runtime</span><span class="p">.</span><span class="na">getExecutor</span><span class="p">(</span><span class="s">&quot;file.exists()&quot;</span><span class="p">).</span><span class="na">executeBoolean</span><span class="p">());</span>
<span class="n">assertEquals</span><span class="p">(</span><span class="n">file</span><span class="p">.</span><span class="na">isFile</span><span class="p">(),</span><span class="w"> </span><span class="n">v8Runtime</span><span class="p">.</span><span class="na">getExecutor</span><span class="p">(</span><span class="s">&quot;file.isFile()&quot;</span><span class="p">).</span><span class="na">executeBoolean</span><span class="p">());</span>
<span class="n">assertEquals</span><span class="p">(</span><span class="n">file</span><span class="p">.</span><span class="na">isDirectory</span><span class="p">(),</span><span class="w"> </span><span class="n">v8Runtime</span><span class="p">.</span><span class="na">getExecutor</span><span class="p">(</span><span class="s">&quot;file.isDirectory()&quot;</span><span class="p">).</span><span class="na">executeBoolean</span><span class="p">());</span>
<span class="n">assertEquals</span><span class="p">(</span><span class="n">file</span><span class="p">.</span><span class="na">canRead</span><span class="p">(),</span><span class="w"> </span><span class="n">v8Runtime</span><span class="p">.</span><span class="na">getExecutor</span><span class="p">(</span><span class="s">&quot;file.canRead()&quot;</span><span class="p">).</span><span class="na">executeBoolean</span><span class="p">());</span>
<span class="n">assertEquals</span><span class="p">(</span><span class="n">file</span><span class="p">.</span><span class="na">canWrite</span><span class="p">(),</span><span class="w"> </span><span class="n">v8Runtime</span><span class="p">.</span><span class="na">getExecutor</span><span class="p">(</span><span class="s">&quot;file.canWrite()&quot;</span><span class="p">).</span><span class="na">executeBoolean</span><span class="p">());</span>
<span class="n">assertEquals</span><span class="p">(</span><span class="n">file</span><span class="p">.</span><span class="na">canExecute</span><span class="p">(),</span><span class="w"> </span><span class="n">v8Runtime</span><span class="p">.</span><span class="na">getExecutor</span><span class="p">(</span><span class="s">&quot;file.canExecute()&quot;</span><span class="p">).</span><span class="na">executeBoolean</span><span class="p">());</span>
<span class="n">v8Runtime</span><span class="p">.</span><span class="na">getGlobalObject</span><span class="p">().</span><span class="na">delete</span><span class="p">(</span><span class="s">&quot;file&quot;</span><span class="p">);</span>
<span class="n">v8Runtime</span><span class="p">.</span><span class="na">lowMemoryNotification</span><span class="p">();</span>
</pre></div>
</div>
</section>
<section id="instance-map">
<h3>Instance: Map<a class="headerlink" href="#instance-map" title="Link to this heading">#</a></h3>
<div class="highlight-java notranslate"><div class="highlight"><pre><span></span><span class="n">javetProxyConverter</span><span class="p">.</span><span class="na">getConfig</span><span class="p">().</span><span class="na">setProxyMapEnabled</span><span class="p">(</span><span class="kc">true</span><span class="p">);</span>
<span class="n">Map</span><span class="o">&lt;</span><span class="n">String</span><span class="p">,</span><span class="w"> </span><span class="n">Object</span><span class="o">&gt;</span><span class="w"> </span><span class="n">map</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="k">new</span><span class="w"> </span><span class="n">HashMap</span><span class="o">&lt;</span><span class="n">String</span><span class="p">,</span><span class="w"> </span><span class="n">Object</span><span class="o">&gt;</span><span class="p">()</span><span class="w"> </span><span class="p">{{</span>
<span class="w">    </span><span class="n">put</span><span class="p">(</span><span class="s">&quot;x&quot;</span><span class="p">,</span><span class="w"> </span><span class="mi">1</span><span class="p">);</span>
<span class="w">    </span><span class="n">put</span><span class="p">(</span><span class="s">&quot;y&quot;</span><span class="p">,</span><span class="w"> </span><span class="s">&quot;2&quot;</span><span class="p">);</span>
<span class="p">}};</span>
<span class="n">v8Runtime</span><span class="p">.</span><span class="na">getGlobalObject</span><span class="p">().</span><span class="na">set</span><span class="p">(</span><span class="s">&quot;map&quot;</span><span class="p">,</span><span class="w"> </span><span class="n">map</span><span class="p">);</span>
<span class="n">assertTrue</span><span class="p">(</span><span class="n">map</span><span class="w"> </span><span class="o">==</span><span class="w"> </span><span class="n">v8Runtime</span><span class="p">.</span><span class="na">getGlobalObject</span><span class="p">().</span><span class="na">getObject</span><span class="p">(</span><span class="s">&quot;map&quot;</span><span class="p">));</span>
<span class="n">assertEquals</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="n">v8Runtime</span><span class="p">.</span><span class="na">getExecutor</span><span class="p">(</span><span class="s">&quot;map[&#39;x&#39;]&quot;</span><span class="p">).</span><span class="na">executeInteger</span><span class="p">());</span>
<span class="n">assertEquals</span><span class="p">(</span><span class="s">&quot;2&quot;</span><span class="p">,</span><span class="w"> </span><span class="n">v8Runtime</span><span class="p">.</span><span class="na">getExecutor</span><span class="p">(</span><span class="s">&quot;map[&#39;y&#39;]&quot;</span><span class="p">).</span><span class="na">executeString</span><span class="p">());</span>
<span class="n">assertEquals</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="n">v8Runtime</span><span class="p">.</span><span class="na">getExecutor</span><span class="p">(</span><span class="s">&quot;map.x&quot;</span><span class="p">).</span><span class="na">executeInteger</span><span class="p">());</span>
<span class="n">assertEquals</span><span class="p">(</span><span class="s">&quot;2&quot;</span><span class="p">,</span><span class="w"> </span><span class="n">v8Runtime</span><span class="p">.</span><span class="na">getExecutor</span><span class="p">(</span><span class="s">&quot;map.y&quot;</span><span class="p">).</span><span class="na">executeString</span><span class="p">());</span>
<span class="n">assertEquals</span><span class="p">(</span><span class="s">&quot;3&quot;</span><span class="p">,</span><span class="w"> </span><span class="n">v8Runtime</span><span class="p">.</span><span class="na">getExecutor</span><span class="p">(</span><span class="s">&quot;map[&#39;z&#39;] = &#39;3&#39;; map.z;&quot;</span><span class="p">).</span><span class="na">executeString</span><span class="p">());</span>
<span class="n">assertEquals</span><span class="p">(</span><span class="s">&quot;3&quot;</span><span class="p">,</span><span class="w"> </span><span class="n">map</span><span class="p">.</span><span class="na">get</span><span class="p">(</span><span class="s">&quot;z&quot;</span><span class="p">));</span>
<span class="n">assertEquals</span><span class="p">(</span><span class="s">&quot;4&quot;</span><span class="p">,</span><span class="w"> </span><span class="n">v8Runtime</span><span class="p">.</span><span class="na">getExecutor</span><span class="p">(</span><span class="s">&quot;map.z = &#39;4&#39;; map.z;&quot;</span><span class="p">).</span><span class="na">executeString</span><span class="p">());</span>
<span class="n">assertEquals</span><span class="p">(</span><span class="s">&quot;4&quot;</span><span class="p">,</span><span class="w"> </span><span class="n">map</span><span class="p">.</span><span class="na">get</span><span class="p">(</span><span class="s">&quot;z&quot;</span><span class="p">));</span>
<span class="n">v8Runtime</span><span class="p">.</span><span class="na">getGlobalObject</span><span class="p">().</span><span class="na">delete</span><span class="p">(</span><span class="s">&quot;map&quot;</span><span class="p">);</span>
<span class="n">v8Runtime</span><span class="p">.</span><span class="na">lowMemoryNotification</span><span class="p">();</span>
<span class="n">javetProxyConverter</span><span class="p">.</span><span class="na">getConfig</span><span class="p">().</span><span class="na">setProxyMapEnabled</span><span class="p">(</span><span class="kc">false</span><span class="p">);</span>
</pre></div>
</div>
</section>
<section id="instance-path">
<h3>Instance: Path<a class="headerlink" href="#instance-path" title="Link to this heading">#</a></h3>
<div class="highlight-java notranslate"><div class="highlight"><pre><span></span><span class="n">Path</span><span class="w"> </span><span class="n">path</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="k">new</span><span class="w"> </span><span class="n">File</span><span class="p">(</span><span class="s">&quot;/tmp/i-am-not-accessible&quot;</span><span class="p">).</span><span class="na">toPath</span><span class="p">();</span>
<span class="n">v8Runtime</span><span class="p">.</span><span class="na">getGlobalObject</span><span class="p">().</span><span class="na">set</span><span class="p">(</span><span class="s">&quot;path&quot;</span><span class="p">,</span><span class="w"> </span><span class="n">path</span><span class="p">);</span>
<span class="n">assertEquals</span><span class="p">(</span><span class="n">path</span><span class="p">,</span><span class="w"> </span><span class="n">v8Runtime</span><span class="p">.</span><span class="na">getGlobalObject</span><span class="p">().</span><span class="na">getObject</span><span class="p">(</span><span class="s">&quot;path&quot;</span><span class="p">));</span>
<span class="n">assertEquals</span><span class="p">(</span><span class="n">path</span><span class="p">.</span><span class="na">toString</span><span class="p">(),</span><span class="w"> </span><span class="n">v8Runtime</span><span class="p">.</span><span class="na">getExecutor</span><span class="p">(</span><span class="s">&quot;path.toString()&quot;</span><span class="p">).</span><span class="na">executeString</span><span class="p">());</span>
<span class="n">Path</span><span class="w"> </span><span class="n">newPath</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">v8Runtime</span><span class="p">.</span><span class="na">toObject</span><span class="p">(</span><span class="n">v8Runtime</span><span class="p">.</span><span class="na">getExecutor</span><span class="p">(</span><span class="s">&quot;path.resolve(&#39;abc&#39;)&quot;</span><span class="p">).</span><span class="na">execute</span><span class="p">(),</span><span class="w"> </span><span class="kc">true</span><span class="p">);</span>
<span class="n">assertNotNull</span><span class="p">(</span><span class="n">newPath</span><span class="p">);</span>
<span class="n">assertEquals</span><span class="p">(</span><span class="n">path</span><span class="p">.</span><span class="na">resolve</span><span class="p">(</span><span class="s">&quot;abc&quot;</span><span class="p">).</span><span class="na">toString</span><span class="p">(),</span><span class="w"> </span><span class="n">newPath</span><span class="p">.</span><span class="na">toString</span><span class="p">());</span>
<span class="n">assertEquals</span><span class="p">(</span><span class="n">path</span><span class="p">.</span><span class="na">resolve</span><span class="p">(</span><span class="s">&quot;abc&quot;</span><span class="p">).</span><span class="na">toString</span><span class="p">(),</span><span class="w"> </span><span class="n">v8Runtime</span><span class="p">.</span><span class="na">getExecutor</span><span class="p">(</span><span class="s">&quot;path.resolve(&#39;abc&#39;).toString()&quot;</span><span class="p">).</span><span class="na">executeString</span><span class="p">());</span>
<span class="n">v8Runtime</span><span class="p">.</span><span class="na">getGlobalObject</span><span class="p">().</span><span class="na">delete</span><span class="p">(</span><span class="s">&quot;path&quot;</span><span class="p">);</span>
<span class="n">v8Runtime</span><span class="p">.</span><span class="na">lowMemoryNotification</span><span class="p">();</span>
</pre></div>
</div>
</section>
<section id="static-stringbuilder">
<h3>Static: StringBuilder<a class="headerlink" href="#static-stringbuilder" title="Link to this heading">#</a></h3>
<div class="highlight-java notranslate"><div class="highlight"><pre><span></span><span class="n">v8Runtime</span><span class="p">.</span><span class="na">getGlobalObject</span><span class="p">().</span><span class="na">set</span><span class="p">(</span><span class="s">&quot;StringBuilder&quot;</span><span class="p">,</span><span class="w"> </span><span class="n">StringBuilder</span><span class="p">.</span><span class="na">class</span><span class="p">);</span>
<span class="n">assertEquals</span><span class="p">(</span><span class="s">&quot;abc def&quot;</span><span class="p">,</span><span class="w"> </span><span class="n">v8Runtime</span><span class="p">.</span><span class="na">getExecutor</span><span class="p">(</span>
<span class="w">        </span><span class="s">&quot;function main() {\n&quot;</span><span class="w"> </span><span class="o">+</span>
<span class="w">                </span><span class="s">&quot;  return new StringBuilder().append(&#39;abc&#39;).append(&#39; &#39;).append(&#39;def&#39;).toString();\n&quot;</span><span class="w"> </span><span class="o">+</span>
<span class="w">                </span><span class="s">&quot;}\n&quot;</span><span class="w"> </span><span class="o">+</span>
<span class="w">                </span><span class="s">&quot;main();&quot;</span><span class="p">).</span><span class="na">executeString</span><span class="p">());</span>
<span class="n">v8Runtime</span><span class="p">.</span><span class="na">getGlobalObject</span><span class="p">().</span><span class="na">delete</span><span class="p">(</span><span class="s">&quot;StringBuilder&quot;</span><span class="p">);</span>
<span class="n">v8Runtime</span><span class="p">.</span><span class="na">lowMemoryNotification</span><span class="p">();</span>
</pre></div>
</div>
</section>
<section id="static-pattern">
<h3>Static: Pattern<a class="headerlink" href="#static-pattern" title="Link to this heading">#</a></h3>
<div class="highlight-java notranslate"><div class="highlight"><pre><span></span><span class="n">v8Runtime</span><span class="p">.</span><span class="na">getGlobalObject</span><span class="p">().</span><span class="na">set</span><span class="p">(</span><span class="s">&quot;Pattern&quot;</span><span class="p">,</span><span class="w"> </span><span class="n">Pattern</span><span class="p">.</span><span class="na">class</span><span class="p">);</span>
<span class="n">assertTrue</span><span class="p">(</span><span class="n">v8Runtime</span><span class="p">.</span><span class="na">getExecutor</span><span class="p">(</span><span class="s">&quot;let p = Pattern.compile(&#39;^\\\\d+$&#39;); p;&quot;</span><span class="p">).</span><span class="na">executeObject</span><span class="p">()</span><span class="w"> </span><span class="k">instanceof</span><span class="w"> </span><span class="n">Pattern</span><span class="p">);</span>
<span class="n">assertTrue</span><span class="p">(</span><span class="n">v8Runtime</span><span class="p">.</span><span class="na">getExecutor</span><span class="p">(</span><span class="s">&quot;p.matcher(&#39;123&#39;).matches();&quot;</span><span class="p">).</span><span class="na">executeBoolean</span><span class="p">());</span>
<span class="n">assertFalse</span><span class="p">(</span><span class="n">v8Runtime</span><span class="p">.</span><span class="na">getExecutor</span><span class="p">(</span><span class="s">&quot;p.matcher(&#39;a123&#39;).matches();&quot;</span><span class="p">).</span><span class="na">executeBoolean</span><span class="p">());</span>
<span class="n">v8Runtime</span><span class="p">.</span><span class="na">getGlobalObject</span><span class="p">().</span><span class="na">delete</span><span class="p">(</span><span class="s">&quot;Pattern&quot;</span><span class="p">);</span>
<span class="n">v8Runtime</span><span class="p">.</span><span class="na">getExecutor</span><span class="p">(</span><span class="s">&quot;p = undefined;&quot;</span><span class="p">).</span><span class="na">executeVoid</span><span class="p">();</span>
<span class="n">v8Runtime</span><span class="p">.</span><span class="na">lowMemoryNotification</span><span class="p">();</span>
</pre></div>
</div>
</section>
<section id="static-enum">
<h3>Static: Enum<a class="headerlink" href="#static-enum" title="Link to this heading">#</a></h3>
<p>Static class usually does not have an instance. The dynamic proxy based converter is smart enough to handle that.</p>
<div class="highlight-java notranslate"><div class="highlight"><pre><span></span><span class="n">v8Runtime</span><span class="p">.</span><span class="na">getGlobalObject</span><span class="p">().</span><span class="na">set</span><span class="p">(</span><span class="s">&quot;JavetErrorType&quot;</span><span class="p">,</span><span class="w"> </span><span class="n">JavetErrorType</span><span class="p">.</span><span class="na">class</span><span class="p">);</span>
<span class="n">assertEquals</span><span class="p">(</span><span class="n">JavetErrorType</span><span class="p">.</span><span class="na">Converter</span><span class="p">,</span><span class="w"> </span><span class="n">v8Runtime</span><span class="p">.</span><span class="na">getExecutor</span><span class="p">(</span><span class="s">&quot;JavetErrorType.Converter&quot;</span><span class="p">).</span><span class="na">executeObject</span><span class="p">());</span>
<span class="n">assertThrows</span><span class="p">(</span>
<span class="w">        </span><span class="n">JavetExecutionException</span><span class="p">.</span><span class="na">class</span><span class="p">,</span>
<span class="w">        </span><span class="p">()</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="n">v8Runtime</span><span class="p">.</span><span class="na">getExecutor</span><span class="p">(</span><span class="s">&quot;JavetErrorType.Converter = 1;&quot;</span><span class="p">).</span><span class="na">executeVoid</span><span class="p">(),</span>
<span class="w">        </span><span class="s">&quot;Public final field should not be writable.&quot;</span><span class="p">);</span>
<span class="n">v8Runtime</span><span class="p">.</span><span class="na">getGlobalObject</span><span class="p">().</span><span class="na">delete</span><span class="p">(</span><span class="s">&quot;JavetErrorType&quot;</span><span class="p">);</span>
<span class="n">v8Runtime</span><span class="p">.</span><span class="na">getGlobalObject</span><span class="p">().</span><span class="na">set</span><span class="p">(</span><span class="s">&quot;Converter&quot;</span><span class="p">,</span><span class="w"> </span><span class="n">JavetErrorType</span><span class="p">.</span><span class="na">Converter</span><span class="p">);</span>
<span class="n">assertEquals</span><span class="p">(</span><span class="n">JavetErrorType</span><span class="p">.</span><span class="na">Converter</span><span class="p">,</span><span class="w"> </span><span class="n">v8Runtime</span><span class="p">.</span><span class="na">getGlobalObject</span><span class="p">().</span><span class="na">getObject</span><span class="p">(</span><span class="s">&quot;Converter&quot;</span><span class="p">));</span>
<span class="n">v8Runtime</span><span class="p">.</span><span class="na">getGlobalObject</span><span class="p">().</span><span class="na">delete</span><span class="p">(</span><span class="s">&quot;Converter&quot;</span><span class="p">);</span>
<span class="n">v8Runtime</span><span class="p">.</span><span class="na">lowMemoryNotification</span><span class="p">();</span>
</pre></div>
</div>
</section>
<section id="static-interface">
<h3>Static: Interface<a class="headerlink" href="#static-interface" title="Link to this heading">#</a></h3>
<p>Sometimes an interface or annotation class can be injected for enabling Java reflection in V8.</p>
<div class="highlight-java notranslate"><div class="highlight"><pre><span></span><span class="n">v8Runtime</span><span class="p">.</span><span class="na">getGlobalObject</span><span class="p">().</span><span class="na">set</span><span class="p">(</span><span class="s">&quot;AutoCloseable&quot;</span><span class="p">,</span><span class="w"> </span><span class="n">AutoCloseable</span><span class="p">.</span><span class="na">class</span><span class="p">);</span>
<span class="n">v8Runtime</span><span class="p">.</span><span class="na">getGlobalObject</span><span class="p">().</span><span class="na">set</span><span class="p">(</span><span class="s">&quot;IJavetClosable&quot;</span><span class="p">,</span><span class="w"> </span><span class="n">IJavetClosable</span><span class="p">.</span><span class="na">class</span><span class="p">);</span>
<span class="n">assertTrue</span><span class="p">(</span><span class="n">AutoCloseable</span><span class="p">.</span><span class="na">class</span><span class="p">.</span><span class="na">isAssignableFrom</span><span class="p">(</span><span class="n">IJavetClosable</span><span class="p">.</span><span class="na">class</span><span class="p">));</span>
<span class="n">assertTrue</span><span class="p">(</span><span class="n">v8Runtime</span><span class="p">.</span><span class="na">getExecutor</span><span class="p">(</span><span class="s">&quot;AutoCloseable.isAssignableFrom(IJavetClosable);&quot;</span><span class="p">).</span><span class="na">executeBoolean</span><span class="p">());</span>
<span class="n">assertEquals</span><span class="p">(</span><span class="n">AutoCloseable</span><span class="p">.</span><span class="na">class</span><span class="p">,</span><span class="w"> </span><span class="n">v8Runtime</span><span class="p">.</span><span class="na">getExecutor</span><span class="p">(</span><span class="s">&quot;AutoCloseable&quot;</span><span class="p">).</span><span class="na">executeObject</span><span class="p">());</span>
<span class="n">assertEquals</span><span class="p">(</span><span class="n">IJavetClosable</span><span class="p">.</span><span class="na">class</span><span class="p">,</span><span class="w"> </span><span class="n">v8Runtime</span><span class="p">.</span><span class="na">getExecutor</span><span class="p">(</span><span class="s">&quot;IJavetClosable&quot;</span><span class="p">).</span><span class="na">executeObject</span><span class="p">());</span>
<span class="n">v8Runtime</span><span class="p">.</span><span class="na">getGlobalObject</span><span class="p">().</span><span class="na">delete</span><span class="p">(</span><span class="s">&quot;AutoCloseable&quot;</span><span class="p">);</span>
<span class="n">v8Runtime</span><span class="p">.</span><span class="na">getGlobalObject</span><span class="p">().</span><span class="na">delete</span><span class="p">(</span><span class="s">&quot;IJavetClosable&quot;</span><span class="p">);</span>
<span class="n">v8Runtime</span><span class="p">.</span><span class="na">lowMemoryNotification</span><span class="p">();</span>
</pre></div>
</div>
</section>
<section id="dynamic-anonymous-function">
<h3>Dynamic: Anonymous Function<a class="headerlink" href="#dynamic-anonymous-function" title="Link to this heading">#</a></h3>
<p>This feature is quite special as it allows implementing Java interfaces in JavaScript via anonymous functions, also known as lambda expressions.</p>
<ol class="arabic simple">
<li><p>Define a simple interface <code class="docutils literal notranslate"><span class="pre">IStringJoiner</span></code> for joining two strings.</p></li>
</ol>
<div class="highlight-java notranslate"><div class="highlight"><pre><span></span><span class="kd">interface</span> <span class="nc">IStringJoiner</span><span class="w"> </span><span class="kd">extends</span><span class="w"> </span><span class="n">AutoCloseable</span><span class="w"> </span><span class="p">{</span>
<span class="w">    </span><span class="n">String</span><span class="w"> </span><span class="nf">join</span><span class="p">(</span><span class="n">String</span><span class="w"> </span><span class="n">a</span><span class="p">,</span><span class="w"> </span><span class="n">String</span><span class="w"> </span><span class="n">b</span><span class="p">);</span>
<span class="p">}</span>
</pre></div>
</div>
<ol class="arabic simple" start="2">
<li><p>Define a simple class <code class="docutils literal notranslate"><span class="pre">StringJoiner</span></code> which holds the interface <code class="docutils literal notranslate"><span class="pre">IStringJoiner</span></code>.</p></li>
</ol>
<div class="highlight-java notranslate"><div class="highlight"><pre><span></span><span class="kd">public</span><span class="w"> </span><span class="kd">class</span> <span class="nc">StringJoiner</span><span class="w"> </span><span class="kd">implements</span><span class="w"> </span><span class="n">AutoCloseable</span><span class="w"> </span><span class="p">{</span>
<span class="w">    </span><span class="kd">private</span><span class="w"> </span><span class="n">IStringJoiner</span><span class="w"> </span><span class="n">joiner</span><span class="p">;</span>

<span class="w">    </span><span class="kd">public</span><span class="w"> </span><span class="nf">StringJoiner</span><span class="p">()</span><span class="w"> </span><span class="p">{</span>
<span class="w">        </span><span class="n">joiner</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="kc">null</span><span class="p">;</span>
<span class="w">    </span><span class="p">}</span>

<span class="w">    </span><span class="nd">@Override</span>
<span class="w">    </span><span class="kd">public</span><span class="w"> </span><span class="kt">void</span><span class="w"> </span><span class="nf">close</span><span class="p">()</span><span class="w"> </span><span class="kd">throws</span><span class="w"> </span><span class="n">Exception</span><span class="w"> </span><span class="p">{</span>
<span class="w">        </span><span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="n">joiner</span><span class="w"> </span><span class="o">!=</span><span class="w"> </span><span class="kc">null</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
<span class="w">            </span><span class="n">joiner</span><span class="p">.</span><span class="na">close</span><span class="p">();</span>
<span class="w">            </span><span class="n">joiner</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="kc">null</span><span class="p">;</span>
<span class="w">        </span><span class="p">}</span>
<span class="w">    </span><span class="p">}</span>

<span class="w">    </span><span class="kd">public</span><span class="w"> </span><span class="n">IStringJoiner</span><span class="w"> </span><span class="nf">getJoiner</span><span class="p">()</span><span class="w"> </span><span class="p">{</span>
<span class="w">        </span><span class="k">return</span><span class="w"> </span><span class="n">joiner</span><span class="p">;</span>
<span class="w">    </span><span class="p">}</span>

<span class="w">    </span><span class="kd">public</span><span class="w"> </span><span class="kt">void</span><span class="w"> </span><span class="nf">setJoiner</span><span class="p">(</span><span class="n">IStringJoiner</span><span class="w"> </span><span class="n">joiner</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
<span class="w">        </span><span class="k">this</span><span class="p">.</span><span class="na">joiner</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">joiner</span><span class="p">;</span>
<span class="w">    </span><span class="p">}</span>
<span class="p">}</span>
</pre></div>
</div>
<ol class="arabic simple" start="3">
<li><p>Inject the implementation from JavaScript.</p></li>
</ol>
<div class="highlight-java notranslate"><div class="highlight"><pre><span></span><span class="k">try</span><span class="w"> </span><span class="p">(</span><span class="n">StringJoiner</span><span class="w"> </span><span class="n">stringJoiner</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="k">new</span><span class="w"> </span><span class="n">StringJoiner</span><span class="p">())</span><span class="w"> </span><span class="p">{</span>
<span class="w">    </span><span class="n">v8Runtime</span><span class="p">.</span><span class="na">getGlobalObject</span><span class="p">().</span><span class="na">set</span><span class="p">(</span><span class="s">&quot;stringJoiner&quot;</span><span class="p">,</span><span class="w"> </span><span class="n">stringJoiner</span><span class="p">);</span>
<span class="w">    </span><span class="n">v8Runtime</span><span class="p">.</span><span class="na">getExecutor</span><span class="p">(</span><span class="s">&quot;stringJoiner.setJoiner((a, b) =&gt; a + &#39;,&#39; + b);&quot;</span><span class="p">).</span><span class="na">executeVoid</span><span class="p">();</span>
<span class="w">    </span><span class="n">IStringJoiner</span><span class="w"> </span><span class="n">joiner</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">stringJoiner</span><span class="p">.</span><span class="na">getJoiner</span><span class="p">();</span>
<span class="w">    </span><span class="n">assertEquals</span><span class="p">(</span><span class="s">&quot;a,b&quot;</span><span class="p">,</span><span class="w"> </span><span class="n">joiner</span><span class="p">.</span><span class="na">join</span><span class="p">(</span><span class="s">&quot;a&quot;</span><span class="p">,</span><span class="w"> </span><span class="s">&quot;b&quot;</span><span class="p">));</span>
<span class="w">    </span><span class="n">assertEquals</span><span class="p">(</span><span class="s">&quot;a,b,c&quot;</span><span class="p">,</span><span class="w"> </span><span class="n">joiner</span><span class="p">.</span><span class="na">join</span><span class="p">(</span><span class="n">joiner</span><span class="p">.</span><span class="na">join</span><span class="p">(</span><span class="s">&quot;a&quot;</span><span class="p">,</span><span class="w"> </span><span class="s">&quot;b&quot;</span><span class="p">),</span><span class="w"> </span><span class="s">&quot;c&quot;</span><span class="p">));</span>
<span class="w">    </span><span class="n">v8Runtime</span><span class="p">.</span><span class="na">getGlobalObject</span><span class="p">().</span><span class="na">delete</span><span class="p">(</span><span class="s">&quot;stringJoiner&quot;</span><span class="p">);</span>
<span class="p">}</span>
<span class="n">v8Runtime</span><span class="p">.</span><span class="na">lowMemoryNotification</span><span class="p">();</span>
</pre></div>
</div>
<p>Voilà! It works.</p>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>The JavaScript implementation is backed up by <code class="docutils literal notranslate"><span class="pre">V8ValueFunction</span></code> which is an orphan object. After its internal <code class="docutils literal notranslate"><span class="pre">V8Runtime</span></code> is closed, it will no longer callable. It's recommended to have the interface implement <code class="docutils literal notranslate"><span class="pre">AutoCloseable</span></code> as the sample shows so that the orphan <code class="docutils literal notranslate"><span class="pre">V8ValueFunction</span></code> can be recycled explicitly. If you don't own the interface, Javet will force the recycle of the orphan <code class="docutils literal notranslate"><span class="pre">V8ValueFunction</span></code> when the <code class="docutils literal notranslate"><span class="pre">V8Runtime</span></code> is being closed. Be careful, if you keep the application running for long while without recycling them in time, <code class="docutils literal notranslate"><span class="pre">OutOfMemoryError</span></code> may occur.</p>
</div>
</section>
<section id="dynamic-anonymous-object-for-interface">
<h3>Dynamic: Anonymous Object for Interface<a class="headerlink" href="#dynamic-anonymous-object-for-interface" title="Link to this heading">#</a></h3>
<p>This feature is similar to the dynamic anonymous function, but is an enhanced version because it allows implementing all methods exposed by a Java interface.</p>
<ol class="arabic simple">
<li><p>Define a simple interface <code class="docutils literal notranslate"><span class="pre">IStringUtils</span></code> for joining two strings.</p></li>
</ol>
<div class="highlight-java notranslate"><div class="highlight"><pre><span></span><span class="kd">interface</span> <span class="nc">IStringUtils</span><span class="w"> </span><span class="kd">extends</span><span class="w"> </span><span class="n">AutoCloseable</span><span class="w"> </span><span class="p">{</span>
<span class="w">    </span><span class="n">String</span><span class="w"> </span><span class="nf">hello</span><span class="p">();</span>
<span class="w">    </span><span class="n">String</span><span class="w"> </span><span class="nf">join</span><span class="p">(</span><span class="n">String</span><span class="w"> </span><span class="n">separator</span><span class="p">,</span><span class="w"> </span><span class="n">String</span><span class="p">...</span><span class="w"> </span><span class="n">strings</span><span class="p">);</span>
<span class="w">    </span><span class="n">List</span><span class="o">&lt;</span><span class="n">String</span><span class="o">&gt;</span><span class="w"> </span><span class="nf">split</span><span class="p">(</span><span class="n">String</span><span class="w"> </span><span class="n">separator</span><span class="p">,</span><span class="w"> </span><span class="n">String</span><span class="w"> </span><span class="n">string</span><span class="p">);</span>
<span class="p">}</span>
</pre></div>
</div>
<ol class="arabic simple" start="2">
<li><p>Define a simple class <code class="docutils literal notranslate"><span class="pre">StringUtils</span></code> which holds the interface <code class="docutils literal notranslate"><span class="pre">IStringUtils</span></code>.</p></li>
</ol>
<div class="highlight-java notranslate"><div class="highlight"><pre><span></span><span class="kd">public</span><span class="w"> </span><span class="kd">class</span> <span class="nc">StringUtils</span><span class="w"> </span><span class="kd">implements</span><span class="w"> </span><span class="n">AutoCloseable</span><span class="w"> </span><span class="p">{</span>
<span class="w">    </span><span class="kd">private</span><span class="w"> </span><span class="n">IStringUtils</span><span class="w"> </span><span class="n">utils</span><span class="p">;</span>

<span class="w">    </span><span class="kd">public</span><span class="w"> </span><span class="nf">StringUtils</span><span class="p">()</span><span class="w"> </span><span class="p">{</span>
<span class="w">        </span><span class="n">utils</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="kc">null</span><span class="p">;</span>
<span class="w">    </span><span class="p">}</span>

<span class="w">    </span><span class="nd">@Override</span>
<span class="w">    </span><span class="kd">public</span><span class="w"> </span><span class="kt">void</span><span class="w"> </span><span class="nf">close</span><span class="p">()</span><span class="w"> </span><span class="kd">throws</span><span class="w"> </span><span class="n">Exception</span><span class="w"> </span><span class="p">{</span>
<span class="w">        </span><span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="n">utils</span><span class="w"> </span><span class="o">!=</span><span class="w"> </span><span class="kc">null</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
<span class="w">            </span><span class="n">utils</span><span class="p">.</span><span class="na">close</span><span class="p">();</span>
<span class="w">            </span><span class="n">utils</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="kc">null</span><span class="p">;</span>
<span class="w">        </span><span class="p">}</span>
<span class="w">    </span><span class="p">}</span>

<span class="w">    </span><span class="kd">public</span><span class="w"> </span><span class="n">IStringUtils</span><span class="w"> </span><span class="nf">getUtils</span><span class="p">()</span><span class="w"> </span><span class="p">{</span>
<span class="w">        </span><span class="k">return</span><span class="w"> </span><span class="n">utils</span><span class="p">;</span>
<span class="w">    </span><span class="p">}</span>

<span class="w">    </span><span class="kd">public</span><span class="w"> </span><span class="kt">void</span><span class="w"> </span><span class="nf">setUtils</span><span class="p">(</span><span class="n">IStringUtils</span><span class="w"> </span><span class="n">utils</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
<span class="w">        </span><span class="k">this</span><span class="p">.</span><span class="na">utils</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">utils</span><span class="p">;</span>
<span class="w">    </span><span class="p">}</span>
<span class="p">}</span>
</pre></div>
</div>
<ol class="arabic simple" start="3">
<li><p>Inject the implementation from JavaScript.</p></li>
</ol>
<div class="highlight-java notranslate"><div class="highlight"><pre><span></span><span class="k">try</span><span class="w"> </span><span class="p">(</span><span class="n">StringUtils</span><span class="w"> </span><span class="n">stringUtils</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="k">new</span><span class="w"> </span><span class="n">StringUtils</span><span class="p">())</span><span class="w"> </span><span class="p">{</span>
<span class="w">    </span><span class="n">v8Runtime</span><span class="p">.</span><span class="na">getGlobalObject</span><span class="p">().</span><span class="na">set</span><span class="p">(</span><span class="s">&quot;stringUtils&quot;</span><span class="p">,</span><span class="w"> </span><span class="n">stringUtils</span><span class="p">);</span>
<span class="w">    </span><span class="n">v8Runtime</span><span class="p">.</span><span class="na">getExecutor</span><span class="p">(</span>
<span class="w">            </span><span class="s">&quot;stringUtils.setUtils({\n&quot;</span><span class="w"> </span><span class="o">+</span>
<span class="w">            </span><span class="s">&quot;  hello: () =&gt; &#39;hello&#39;,\n&quot;</span><span class="w"> </span><span class="o">+</span>
<span class="w">            </span><span class="s">&quot;  join: (separator, ...strings) =&gt; [...strings].join(separator),\n&quot;</span><span class="w"> </span><span class="o">+</span>
<span class="w">            </span><span class="s">&quot;  split: (separator, str) =&gt; str.split(separator),\n&quot;</span><span class="w"> </span><span class="o">+</span>
<span class="w">            </span><span class="s">&quot;});&quot;</span>
<span class="w">    </span><span class="p">).</span><span class="na">executeVoid</span><span class="p">();</span>
<span class="w">    </span><span class="n">IStringUtils</span><span class="w"> </span><span class="n">utils</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">stringUtils</span><span class="p">.</span><span class="na">getUtils</span><span class="p">();</span>
<span class="w">    </span><span class="n">assertEquals</span><span class="p">(</span><span class="s">&quot;hello&quot;</span><span class="p">,</span><span class="w"> </span><span class="n">utils</span><span class="p">.</span><span class="na">hello</span><span class="p">());</span>
<span class="w">    </span><span class="n">assertEquals</span><span class="p">(</span><span class="s">&quot;a,b,c&quot;</span><span class="p">,</span><span class="w"> </span><span class="n">utils</span><span class="p">.</span><span class="na">join</span><span class="p">(</span><span class="s">&quot;,&quot;</span><span class="p">,</span><span class="w"> </span><span class="s">&quot;a&quot;</span><span class="p">,</span><span class="w"> </span><span class="s">&quot;b&quot;</span><span class="p">,</span><span class="w"> </span><span class="s">&quot;c&quot;</span><span class="p">));</span>
<span class="w">    </span><span class="n">assertArrayEquals</span><span class="p">(</span>
<span class="w">            </span><span class="k">new</span><span class="w"> </span><span class="n">String</span><span class="o">[]</span><span class="p">{</span><span class="s">&quot;a&quot;</span><span class="p">,</span><span class="w"> </span><span class="s">&quot;b&quot;</span><span class="p">,</span><span class="w"> </span><span class="s">&quot;c&quot;</span><span class="p">},</span>
<span class="w">            </span><span class="n">utils</span><span class="p">.</span><span class="na">split</span><span class="p">(</span><span class="s">&quot;,&quot;</span><span class="p">,</span><span class="w"> </span><span class="s">&quot;a,b,c&quot;</span><span class="p">).</span><span class="na">toArray</span><span class="p">(</span><span class="k">new</span><span class="w"> </span><span class="n">String</span><span class="o">[</span><span class="mi">0</span><span class="o">]</span><span class="p">));</span>
<span class="w">    </span><span class="n">v8Runtime</span><span class="p">.</span><span class="na">getGlobalObject</span><span class="p">().</span><span class="na">delete</span><span class="p">(</span><span class="s">&quot;stringUtils&quot;</span><span class="p">);</span>
<span class="p">}</span>
<span class="n">v8Runtime</span><span class="p">.</span><span class="na">lowMemoryNotification</span><span class="p">();</span>
</pre></div>
</div>
<p>Voilà aussi! It works again.</p>
</section>
<section id="dynamic-anonymous-object-for-class">
<h3>Dynamic: Anonymous Object for Class<a class="headerlink" href="#dynamic-anonymous-object-for-class" title="Link to this heading">#</a></h3>
<p>This feature is similar to the dynamic anonymous object for interface, but it allows implementing all methods exposed by a non-final Java class.</p>
<ol class="arabic simple">
<li><p>Add <code class="docutils literal notranslate"><span class="pre">ByteBuddy</span></code> to the dependency. You may skip this step if your project has already referenced <code class="docutils literal notranslate"><span class="pre">ByteBuddy</span></code>.</p></li>
</ol>
<div class="highlight-xml notranslate"><div class="highlight"><pre><span></span><span class="cm">&lt;!-- Maven --&gt;</span>
<span class="nt">&lt;dependency&gt;</span>
<span class="w">    </span><span class="nt">&lt;groupId&gt;</span>net.bytebuddy<span class="nt">&lt;/groupId&gt;</span>
<span class="w">    </span><span class="nt">&lt;artifactId&gt;</span>byte-buddy<span class="nt">&lt;/artifactId&gt;</span>
<span class="w">    </span><span class="nt">&lt;version&gt;</span>1.12.17<span class="nt">&lt;/version&gt;</span>
<span class="nt">&lt;/dependency&gt;</span>
</pre></div>
</div>
<div class="highlight-kotlin notranslate"><div class="highlight"><pre><span></span><span class="c1">// Gradle Kotlin DSL</span>
<span class="n">implementation</span><span class="p">(</span><span class="s">&quot;net.bytebuddy:byte-buddy:1.12.17&quot;</span><span class="p">)</span>
</pre></div>
</div>
<div class="highlight-groovy notranslate"><div class="highlight"><pre><span></span><span class="c1">// Gradle Groovy DSL</span>
<span class="n">implementation</span><span class="w"> </span><span class="s1">&#39;net.bytebuddy:byte-buddy:1.12.17&#39;</span>
</pre></div>
</div>
<ol class="arabic simple" start="2">
<li><p>Copy <a class="reference external" href="https://github.com/caoccao/Javet/tree/main/1/2/3/../../../src/test/java/com/caoccao/javet/interop/proxy/JavetDynamicObjectFactory.java">JavetDynamicObjectFactory.java</a> to your project. As Javet doesn't reference <code class="docutils literal notranslate"><span class="pre">ByteBuddy</span></code> directly, <code class="docutils literal notranslate"><span class="pre">JavetDynamicObjectFactory</span></code> has to stay at the test project.</p></li>
<li><p>Define a simple class <code class="docutils literal notranslate"><span class="pre">DynamicClass</span></code> for adding two integers.</p></li>
</ol>
<div class="highlight-java notranslate"><div class="highlight"><pre><span></span><span class="kd">public</span><span class="w"> </span><span class="kd">class</span> <span class="nc">DynamicClass</span><span class="w"> </span><span class="p">{</span>
<span class="w">    </span><span class="kd">public</span><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="nf">add</span><span class="p">(</span><span class="kt">int</span><span class="w"> </span><span class="n">a</span><span class="p">,</span><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="n">b</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
<span class="w">        </span><span class="k">return</span><span class="w"> </span><span class="mi">0</span><span class="p">;</span>
<span class="w">    </span><span class="p">}</span>
<span class="p">}</span>
</pre></div>
</div>
<ol class="arabic simple" start="4">
<li><p>Create an instance of a class which takes an instance of the <code class="docutils literal notranslate"><span class="pre">DynamicClass</span></code>.</p></li>
</ol>
<div class="highlight-java notranslate"><div class="highlight"><pre><span></span><span class="n">IJavetAnonymous</span><span class="w"> </span><span class="n">anonymous</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="k">new</span><span class="w"> </span><span class="n">IJavetAnonymous</span><span class="p">()</span><span class="w"> </span><span class="p">{</span>
<span class="w">    </span><span class="nd">@V8Function</span>
<span class="w">    </span><span class="kd">public</span><span class="w"> </span><span class="kt">void</span><span class="w"> </span><span class="nf">test</span><span class="p">(</span><span class="n">DynamicClass</span><span class="w"> </span><span class="n">dynamicClass</span><span class="p">)</span><span class="w"> </span><span class="kd">throws</span><span class="w"> </span><span class="n">Exception</span><span class="w"> </span><span class="p">{</span>
<span class="w">        </span><span class="n">assertEquals</span><span class="p">(</span><span class="mi">3</span><span class="p">,</span><span class="w"> </span><span class="n">dynamicClass</span><span class="p">.</span><span class="na">add</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="mi">2</span><span class="p">),</span><span class="w"> </span><span class="s">&quot;Add should work.&quot;</span><span class="p">);</span>
<span class="w">        </span><span class="p">((</span><span class="n">AutoCloseable</span><span class="p">)</span><span class="w"> </span><span class="n">dynamicClass</span><span class="p">).</span><span class="na">close</span><span class="p">();</span>
<span class="w">    </span><span class="p">}</span>
<span class="p">};</span>
</pre></div>
</div>
<ol class="arabic simple" start="5">
<li><p>Inject the implementation from JavaScript. Please note that dynamic object support is disabled by default and <code class="docutils literal notranslate"><span class="pre">JavetDynamicObjectFactory</span></code> needs to be set to the converter config for <code class="docutils literal notranslate"><span class="pre">JavetProxyConverter</span></code> to enable this feature.</p></li>
</ol>
<div class="highlight-java notranslate"><div class="highlight"><pre><span></span><span class="k">try</span><span class="w"> </span><span class="p">{</span>
<span class="w">    </span><span class="n">javetProxyConverter</span><span class="p">.</span><span class="na">getConfig</span><span class="p">().</span><span class="na">setDynamicObjectFactory</span><span class="p">(</span><span class="n">JavetDynamicObjectFactory</span><span class="p">.</span><span class="na">getInstance</span><span class="p">());</span>
<span class="w">    </span><span class="n">v8Runtime</span><span class="p">.</span><span class="na">getGlobalObject</span><span class="p">().</span><span class="na">set</span><span class="p">(</span><span class="s">&quot;a&quot;</span><span class="p">,</span><span class="w"> </span><span class="n">anonymous</span><span class="p">);</span>
<span class="w">    </span><span class="n">String</span><span class="w"> </span><span class="n">codeString</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s">&quot;a.test({\n&quot;</span><span class="w"> </span><span class="o">+</span>
<span class="w">            </span><span class="s">&quot;  add: (a, b) =&gt; a + b,\n&quot;</span><span class="w"> </span><span class="o">+</span>
<span class="w">            </span><span class="s">&quot;});&quot;</span><span class="p">;</span>
<span class="w">    </span><span class="n">v8Runtime</span><span class="p">.</span><span class="na">getExecutor</span><span class="p">(</span><span class="n">codeString</span><span class="p">).</span><span class="na">executeVoid</span><span class="p">();</span>
<span class="w">    </span><span class="n">v8Runtime</span><span class="p">.</span><span class="na">getGlobalObject</span><span class="p">().</span><span class="na">delete</span><span class="p">(</span><span class="s">&quot;a&quot;</span><span class="p">);</span>
<span class="p">}</span><span class="w"> </span><span class="k">finally</span><span class="w"> </span><span class="p">{</span>
<span class="w">    </span><span class="n">javetProxyConverter</span><span class="p">.</span><span class="na">getConfig</span><span class="p">().</span><span class="na">setDynamicObjectFactory</span><span class="p">(</span><span class="kc">null</span><span class="p">);</span>
<span class="w">    </span><span class="n">v8Runtime</span><span class="p">.</span><span class="na">lowMemoryNotification</span><span class="p">();</span>
<span class="p">}</span>
</pre></div>
</div>
<p>Voilà aussi! It works again.</p>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>The JavaScript implementation is backed up by <code class="docutils literal notranslate"><span class="pre">V8ValueObject</span></code> which is an orphan object. After its internal <code class="docutils literal notranslate"><span class="pre">V8Runtime</span></code> is closed, it will no longer callable. It's recommended to have the interface implement <code class="docutils literal notranslate"><span class="pre">AutoCloseable</span></code> as the sample shows so that the orphan <code class="docutils literal notranslate"><span class="pre">V8ValueObject</span></code> can be recycled explicitly. If you don't own the interface, Javet will force the recycle of the orphan <code class="docutils literal notranslate"><span class="pre">V8ValueObject</span></code> when the <code class="docutils literal notranslate"><span class="pre">V8Runtime</span></code> is being closed. Be careful, if you keep the application running for long while without recycling them in time, <code class="docutils literal notranslate"><span class="pre">OutOfMemoryError</span></code> may occur.</p>
</div>
</section>
</section>
<section id="features">
<h2>Features<a class="headerlink" href="#features" title="Link to this heading">#</a></h2>
<ul class="simple">
<li><p>Any Java objects generated inside V8 are automatically handled by the converter.</p></li>
<li><p>Getters and setters (<code class="docutils literal notranslate"><span class="pre">get</span></code>, <code class="docutils literal notranslate"><span class="pre">is</span></code>, <code class="docutils literal notranslate"><span class="pre">set</span></code> and <code class="docutils literal notranslate"><span class="pre">put</span></code>) are smartly handled.</p></li>
<li><p>Overloaded methods and varargs methods are identified well.</p></li>
<li><p>Primitive types, Set, Map, List, Array are not handled. Map is special because it can be enabled.</p></li>
<li><p>Java interfaces can be implemented by anonymous functions in JavaScript.</p></li>
<li><p>Annotations can be applied to classes or methods to alter the default behaviors.</p></li>
</ul>
<div class="table-wrapper docutils container">
<table class="docutils align-default">
<thead>
<tr class="row-odd"><th class="head"><p>Annotation</p></th>
<th class="head"><p>Type</p></th>
<th class="head"><p>Description</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p>&#64;V8Convert</p></td>
<td><p>Class</p></td>
<td><p>It tells the converter which mode to be applied to the annotated class.</p></td>
</tr>
<tr class="row-odd"><td><p>&#64;V8Allow</p></td>
<td><p>Constructor / Field / Method</p></td>
<td><p>It tells the converter to bind the constructor / field / method.</p></td>
</tr>
<tr class="row-even"><td><p>&#64;V8Block</p></td>
<td><p>Constructor / Field / Method</p></td>
<td><p>It tells the converter to ignore the constructor / field / method.</p></td>
</tr>
<tr class="row-odd"><td><p>&#64;V8Property</p></td>
<td><p>Field</p></td>
<td><p>It tells the converter to bind the field.</p></td>
</tr>
<tr class="row-even"><td><p>&#64;V8Function</p></td>
<td><p>Method</p></td>
<td><p>It tells the converter to bind the method.</p></td>
</tr>
<tr class="row-odd"><td><p>&#64;V8Getter</p></td>
<td><p>Method</p></td>
<td><p>It tells the converter to bind the method as getter.</p></td>
</tr>
<tr class="row-even"><td><p>&#64;V8Setter</p></td>
<td><p>Method</p></td>
<td><p>It tells the converter to bind the method as setter.</p></td>
</tr>
</tbody>
</table>
</div>
<section id="v8convert-mode">
<h3>&#64;V8Convert::mode<a class="headerlink" href="#v8convert-mode" title="Link to this heading">#</a></h3>
<p>It tells the converter how to treat the annotated class.</p>
<ul class="simple">
<li><p>Transparent - Transparent mode maps the Java objects directly to V8 and ignores any annotations. It is the default mode.</p></li>
<li><p>AllowOnly - AllowOnly mode only maps the API with <code class="docutils literal notranslate"><span class="pre">&#64;V8Allow</span></code>.</p></li>
<li><p>BlockOnly - BlockOnly mode only ignores the API with <code class="docutils literal notranslate"><span class="pre">&#64;V8Block</span></code>.</p></li>
</ul>
</section>
<section id="v8property-name">
<h3>&#64;V8Property::name<a class="headerlink" href="#v8property-name" title="Link to this heading">#</a></h3>
<p>It tells the converter to bind the property to an alias name.</p>
</section>
<section id="v8function-name">
<h3>&#64;V8Function::name<a class="headerlink" href="#v8function-name" title="Link to this heading">#</a></h3>
<p>It tells the converter to bind the function to an alias name.</p>
</section>
</section>
<section id="how-does-javetproxyconverter-work">
<h2>How does JavetProxyConverter Work?<a class="headerlink" href="#how-does-javetproxyconverter-work" title="Link to this heading">#</a></h2>
<p><code class="docutils literal notranslate"><span class="pre">JavetProxyConverter</span></code> creates a JavaScript proxy per Java object. For now, the proxy intercepts <code class="docutils literal notranslate"><span class="pre">get</span></code>, <code class="docutils literal notranslate"><span class="pre">has</span></code> and <code class="docutils literal notranslate"><span class="pre">set</span></code> to achieve the complete virtualization of Java objects in JavaScript runtime.</p>
</section>
<section id="how-to-customize-javetproxyconverter">
<h2>How to Customize JavetProxyConverter?<a class="headerlink" href="#how-to-customize-javetproxyconverter" title="Link to this heading">#</a></h2>
<p>It is recommended to subclass <code class="docutils literal notranslate"><span class="pre">JavetProxyConverter</span></code> and override few internal API to achieve complete customization.</p>
</section>
</section>

        </article>
      </div>
      <footer>
        
        <div class="related-pages">
          <a class="next-page" href="bridge_converter.html">
              <div class="page-info">
                <div class="context">
                  <span>Next</span>
                </div>
                <div class="title">Bridge Converter</div>
              </div>
              <svg class="furo-related-icon"><use href="#svg-arrow-right"></use></svg>
            </a>
          <a class="prev-page" href="object_converter.html">
              <svg class="furo-related-icon"><use href="#svg-arrow-right"></use></svg>
              <div class="page-info">
                <div class="context">
                  <span>Previous</span>
                </div>
                
                <div class="title">Object Converter</div>
                
              </div>
            </a>
        </div>
        <div class="bottom-of-page">
          <div class="left-details">
            <div class="copyright">
                Copyright &#169; 2021-2023. caoccao.com Sam Cao
            </div>
            Made with 
            <a href="https://github.com/pradyunsg/furo">Furo</a>
            
          </div>
          <div class="right-details">
            
          </div>
        </div>
        
      </footer>
    </div>
    <aside class="toc-drawer">
      
      
      <div class="toc-sticky toc-scroll">
        <div class="toc-title-container">
          <span class="toc-title">
            On this page
          </span>
        </div>
        <div class="toc-tree-container">
          <div class="toc-tree">
            <ul>
<li><a class="reference internal" href="#">Proxy Converter</a><ul>
<li><a class="reference internal" href="#usage">Usage</a><ul>
<li><a class="reference internal" href="#preparation">Preparation</a></li>
<li><a class="reference internal" href="#instance-file">Instance: File</a></li>
<li><a class="reference internal" href="#instance-map">Instance: Map</a></li>
<li><a class="reference internal" href="#instance-path">Instance: Path</a></li>
<li><a class="reference internal" href="#static-stringbuilder">Static: StringBuilder</a></li>
<li><a class="reference internal" href="#static-pattern">Static: Pattern</a></li>
<li><a class="reference internal" href="#static-enum">Static: Enum</a></li>
<li><a class="reference internal" href="#static-interface">Static: Interface</a></li>
<li><a class="reference internal" href="#dynamic-anonymous-function">Dynamic: Anonymous Function</a></li>
<li><a class="reference internal" href="#dynamic-anonymous-object-for-interface">Dynamic: Anonymous Object for Interface</a></li>
<li><a class="reference internal" href="#dynamic-anonymous-object-for-class">Dynamic: Anonymous Object for Class</a></li>
</ul>
</li>
<li><a class="reference internal" href="#features">Features</a><ul>
<li><a class="reference internal" href="#v8convert-mode">&#64;V8Convert::mode</a></li>
<li><a class="reference internal" href="#v8property-name">&#64;V8Property::name</a></li>
<li><a class="reference internal" href="#v8function-name">&#64;V8Function::name</a></li>
</ul>
</li>
<li><a class="reference internal" href="#how-does-javetproxyconverter-work">How does JavetProxyConverter Work?</a></li>
<li><a class="reference internal" href="#how-to-customize-javetproxyconverter">How to Customize JavetProxyConverter?</a></li>
</ul>
</li>
</ul>

          </div>
        </div>
      </div>
      
      
    </aside>
  </div>
</div><script src="../../_static/documentation_options.js?v=5e0dd536"></script>
    <script src="../../_static/doctools.js?v=888ff710"></script>
    <script src="../../_static/sphinx_highlight.js?v=dc90522c"></script>
    <script src="../../_static/scripts/furo.js?v=32e29ea5"></script>
    <script src="../../_static/tabs.js?v=3ee01567"></script>
    </body>
</html>